<template>
    <view class="app">
        <load :ready="ready"></load>
		<view class="bill-list">
			<view class="item" v-for="(item, index) in list" :key="item.id">
				<view class="name">
					发票类型：{{item.invoiceTypeName}}
				</view>	
				<view class="text">
					开票类型：{{item.billingTypeName}}
				</view>
				<template v-if="item.billingType == 1">
					<view class="text">
						姓名：{{item.name}}
					</view>
				</template>
				<template v-if="item.billingType == 2">
					<view class="text">
						单位名称：{{item.name}}
					</view>
					<view class="text">
						纳税人识别号：{{item.taxpayerNumber}}
					</view>
				</template>
				
				<view class="text">
					邮箱：{{item.email}}
				</view>
				
				<view class="desc-foot">
					<u-button plain  type="error" size="mini" shape="circle" :custom-style="customStyle" @click="handleDel(item, index)">删除</u-button>
					<u-button @click="link(`./bill_form?id=${item.id}`)" type="primary" size="mini" shape="circle" :custom-style="customStyle">编辑</u-button>
				</view>
			</view>
		</view>	
		
		<list-tip :notData="listTip.notData" :isPage="listTip.isPage" :isLoading="listTip.isLoading">
		    <u-empty slot="notdata" text="暂无数据"  margin-top="100"></u-empty>
		</list-tip>
		
		<u-gap height="160"></u-gap>
		<view class="btnbox fixed">
			<u-button type="primary" @click="link(`./bill_form`)" shape="circle" :custom-style="btnStyle">添加开票</u-button>
		</view>
		
		<u-modal v-model="showDel" content="是否确定删除？" :show-cancel-button="true" @confirm="handleConfirmDel" ref="uModal" :async-close="true"></u-modal>
		
		
	</view>
</template>

<script>
import { mapState, mapActions, mapMutations, mapGetters } from 'vuex';
import { mixinsBase } from '@/common/js/mixins';
let that;
export default {
    mixins: [mixinsBase],
    components: {},
    data() {
        return {
			btnStyle:this.$config.btnStyle,
			billType: 1,
			customStyle:{
				fontSize: '13px',
				padding: '6px 15px',
				margin: '0 0 0 8px'
			},
			listTip: {},
			list:[],
			info:{},
			showDel: false,
        };
    },
    onLoad() {
        that = this;
    },
    onReady() {
    },
    onShow() {
       this.$list.init(this);
       this.getList();
    },
    onUnload() {
        that = null;
    },
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function() {
        // this.getInit(data=>{
        //      uni.stopPullDownRefresh();
        //      common.showTip('刷新成功');
        // });
    },

    /**
     * 页面上拉触底事件的处理函数
     */
   onReachBottom: function() {
   	this.$list.onReachBottom(this)
   },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function() {
        //       return {
        // 	// path,
        // 	imageUrl:config.shareImg,
        // 	// title
        // }
    },
    methods: {
		async handleConfirmDel(){
			uni.showLoading({
				mask:true
			});
			const  res = await this.$api.billingRemove({
				id: this.info.id,
			});
			uni.hideLoading();
			if (res.data.code == this.$config.RESOK) {
				this.showDel = false;
				this.$common.showTip(res.data.msg)
				this.list.splice(this.info.index, 1)
			} else{
				this.$common.showTip(res.data.msg, 'none')
			}
		},
		handleDel(item, index){
			this.showDel = true;
			this.info = {
				...item,
				index,
			}
		},
		async getList() {
		    let listTip = this.listTip;
		    let res = {};
		    let params = {
		        pageNum: listTip.p,
		        pageSize: listTip.size,
		    };
		    try {
		        res = await this.$api.billingList(params);
		    } catch (e) {
		        uni.hideLoading();
		        console.log('err', e);
		    }
		    if (res.data.code == this.$config.RESOK) {
		        let list = res.data.rows || [];
		        let setdata = this.$list.normalData(list, this);
				console.log(setdata);
		        this.list = setdata.list;
		        this.listTip = setdata.listTip;
		        if (setdata.list.length >= res.data.total && listTip.p > 1 || !list.length) {
		            this.$list.notdata(this);
		        } 
		    } 
		},
        ...mapActions([])
    },
    computed: {
        ...mapState({
            userInfo: 'userInfo'
        })
    }
};
</script>

<style scoped lang="scss">
page {
    background-color: #F8FAFD;
}
.bill-list{
	padding: 30rpx 32rpx 0;
	.item{
		background: #fff;
		border-radius: 12px;
		margin-bottom: 12px;
		padding: 12px 20px;
		border: 2px solid #fff;
		overflow: hidden;
		position: relative;
		.icons{
			position: absolute;
			right: 0;
			padding: 2px 5px;
			background: $color;
			bottom: 0;
			display: none;
		}
		&.active{
			.icons{
				display: block;
			}
			border-color: $color;
		}
	}
	.name{
		font-size: 14px;
		margin-bottom: 6px;
		font-weight: bold;
	}
	.text{
		margin-bottom: 6px;
	}
	
	.desc-foot{
		border-top: 1px solid #ddd;
		padding-top: 20rpx;
		text-align: right;
	}
}
</style>
